package com.lzw.security.service.impl;

import com.lzw.security.entity.*;
import com.lzw.security.exception.MysqlUpdateException;
import com.lzw.security.exception.TidcNulException;
import com.lzw.security.mapper.*;
import com.lzw.security.ov.Status;
import com.lzw.security.ov.UserOV;
import com.lzw.security.service.DeleteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-3-28 22:33
 * @description：
 * @modified By：
 * @version:
 */
@Service
@Slf4j
public class DeleteServiceImpl implements DeleteService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private CommodityMapper commodityMapper;
    @Autowired
    private SeckillMapper seckillMapper;
    @Autowired
    private DosingMapper dosingMapper;
    @Autowired
    private CartMapper cartMapper;
    @Autowired
    private AccessoryMapper accessoryMapper;
    @Autowired
    private CouponMapper couponMapper;
    @Override
    public UserOV<Integer> deleteCategory(Category category) throws TidcNulException {
        UserOV<Integer> userOV = new UserOV<>();
        if(category.getId()!=null){
            userOV.setData(categoryMapper.deleteCategory(category.getId()));
            userOV.getMeta().setStatus(200);
        }else{
            log.debug("想删除类别但是没有输入id");
            throw new TidcNulException("删除类别必须要指定");
        }
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteCommodity(Commodity commodity)  {
        UserOV<Integer> userOV = new UserOV<>();
        userOV.setData(commodityMapper.deleteCommodity(commodity.getId())).getMeta().setStatus(200);
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteSectill(Seckill seckill) {
        UserOV<Integer> userOV = new UserOV<>();
        userOV.setData(seckillMapper.deleteSectill(seckill.getId())).getMeta().setStatus(200);
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteDosing(Dosing dosing) {
        UserOV<Integer> userOV = new UserOV<>();
        dosingMapper.deleteAccessoryDosingAll(dosing.getId());
        userOV.setData(dosingMapper.deleteDosing(dosing.getId())).getMeta().setStatus(200);
        return userOV;
    }

//    @Override
//    public UserOV<Integer> deleteDosingInCommodity(DosingCommodity dosingCommodity) {
//        UserOV<Integer> userOV = new UserOV<>();
//        userOV.setData(commodityMapper.deleteDosingInCommodity(dosingCommodity)).getMeta().setStatus(200);
//        return userOV;
//    }

    @Override
    public UserOV<Integer> deleteCart(Cart cart) {
        UserOV<Integer> userOV = new UserOV<>();
        userOV.setData(cartMapper.deleteCart(cart.getId())).getMeta().setStatus(200);
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteAccessoryDosing(AccessoryDosing accessoryDosing) {
        UserOV<Integer> userOV = new UserOV<>();
        userOV.setData(accessoryMapper.deleteAccessoryDosing(accessoryDosing)).getMeta().setStatus(200);
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteCommodityAccessory(CommodityAccessory commodityAccessory) {
        UserOV<Integer> userOV = new UserOV<>();
        userOV.setData(commodityMapper.deleteCommodityAccessory(commodityAccessory)).getMeta().setStatus(200);
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteAccessory(Accessory accessory) {
        UserOV<Integer> userOV = new UserOV<>();
        accessoryMapper.deleteAccessoryDosingAll(accessory.getId());
        userOV.setData(accessoryMapper.deleteAccessory(accessory.getId())).getMeta().setStatus(200);
        return userOV;
    }

    @Override
    public UserOV<Integer> deleteCoupon(Coupon coupon) {
        UserOV<Integer> userOV = new UserOV<>();
        userOV.setData(couponMapper.deleteCoupon(coupon.getId())).getMeta().setStatus(200);
        return userOV;
    }

}
